package simple;


import sword.offer.common.GenerateList;
import sword.offer.common.ListNode;

public class RemoveLinkedListElements {
    public static void main(String[] args) {
        ListNode generate = GenerateList.generate(new int[]{1, 2, 6, 3, 4, 5, 6});
        Solution solution = new Solution();
        solution.removeElements(generate,6);
    }

    static class Solution {
        public ListNode removeElements(ListNode head, int val) {
            ListNode dummyNode = new ListNode(0);
            dummyNode.next = head;
            ListNode pre = dummyNode;
            ListNode cur = head;
            while(cur != null){
                if(cur.val == val){
                    pre.next = cur.next;
                }else{
                    pre = pre.next;
                }
                cur = cur.next;
            }
            return dummyNode.next;
        }
    }
}
